package com.then.component.login.ui.register;

import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.ViewModel;

import com.blankj.utilcode.util.EncryptUtils;
import com.then.architecture.data.dto.Resource;
import com.then.component.login.dto.Auth;
import com.then.component.login.dto.Login;
import com.then.component.login.dto.LoginSimpleEntity;
import com.then.component.login.repository.LoginRepository;
import com.then.component.login.request.CompleteFindPwdReq;
import com.then.component.login.request.FindPwdReq;
import com.then.component.login.request.IsPhoneRegisterReq;
import com.then.component.login.request.RegisterReq;
import com.then.component.login.request.SendSmsReq;

import javax.inject.Inject;

/**
 * Created by 42524 on 2018/1/11.
 */

public class RegisterActivityViewModel extends ViewModel {

    LoginRepository loginRepository;

    @Inject
    public RegisterActivityViewModel(LoginRepository loginRepository) {
        this.loginRepository = loginRepository;
    }


    public LiveData<Resource<LoginSimpleEntity>> isPhoneRegister(String phone, String country) {
        return loginRepository.isPhoneRegistered(new IsPhoneRegisterReq(phone, country));
    }

    public LiveData<Resource<LoginSimpleEntity>> sendSms(String phone) {
        return loginRepository.sendSms(new SendSmsReq(phone));
    }

    public LiveData<Resource<Auth>> register(String phoneNumber, String pwd, String captcha, String country, String inviteCode) {
        return loginRepository.register(new RegisterReq(country, phoneNumber, captcha, EncryptUtils.encryptMD5ToString(pwd).toLowerCase(), inviteCode));
    }

    public LiveData<Resource<Login>> completePhoneFindPwd(String country, String phoneNum, String authCode, String pwd, String pwdAgain) {
        return loginRepository.completePhoneFindPwd(new CompleteFindPwdReq(country, phoneNum, authCode, EncryptUtils.encryptMD5ToString(pwd).toLowerCase(), EncryptUtils.encryptMD5ToString(pwdAgain).toLowerCase()));
    }

    public LiveData<Resource<Auth>> findPwd(String country, String phoneNum, String vcode) {
        return loginRepository.findPwd(new FindPwdReq(country, phoneNum, vcode));
    }

}
